<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false" %>
<%@ include file="/include/taglibs.jsp" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
    pageContext.setAttribute("base", basePath);
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <!-- <meta name=”renderer” content=”webkit|ie-comp|ie-stand” /> -->
    <%--<meta name="renderer" content="webkit"/>--%>
    <title>Oauth2验证平台</title>
    <meta name="description" content="User login page"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <%-- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>--%>
    <base href="<%=basePath%>"/>
    <%--<meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="cache-control" content="no-cache"/>
    <meta http-equiv="expires" content="0"/>
    <meta http-equiv="keywords" content=""/>--%>
    <%--<meta http-equiv="description" content="青岛工业软件研究所CSCW"/>--%>
    <link type="text/css" rel="stylesheet" href="${ctx}/assets/admin/LingUI/login/css/login.css">
    <script src="${ctx}/assets/admin/LingUI/js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="${ctx}/assets/admin/LingUI/js/jquery.backstretch.min.js"></script>
    <script src="${ctx}/assets/admin/LingUI/js/jquery.placeholder.min.js"></script>
    <script type="text/javascript" src="${ctx}/assets/admin/LingUI/js/jsutil/browser.js"></script>
    <!--[if lte IE 8]>
    <style>
        body {
            overflow-x: hidden;
        }

        input {
            line-height: 43px;
        }
    </style>
    <![endif]-->
</head>


<body>
<div class="topk">
    <div class="top">
        <div class="top-fl">
            <div class="logo" style="margin-top:6px; ">
                <%--<img src="${base}/assets/admin/LingUI/login/images/logor.png"/>--%>
                <span style="line-height: 50px;font-family: '微软雅黑';font-size:24px;color:#004A90">Oauth2验证平台</span>
            </div>
        </div>
        <div class="top-fr">
            <p>全国服务热线：<span>XXXXXX</span></p>
        </div>
    </div>
</div>

<div class="login-con">
    <div class="login-confl">
        <img src="${ctx}/assets/admin/LingUI/login/images/login-pic.png">
    </div>
    <div class="login-confr">
        <h1>用户登录</h1>
        <form id="form" name="form" <%--action="${base}/login?loginType=bu"--%> method="post" onsubmit="return check();">

            <input type="text" name="username" id="username" class="username" placeholder="用户名" value="">
            <input type="password" name="password" id="password" class="password" placeholder="密码" value="">
            <input type="text" id="verificationCode" name="verificationCode" class="yanzhengma" placeholder="输入验证码的计算结果" value="" autocomplete="off">
            <img class="yzm" id="captchaImage" src="${ctx}/genVerCode" onclick="changeCode()" alt="换一张"  style="cursor:pointer">
            <div class="jzmm"><input type="checkbox" id="rememberMe" name="rememberMe" value="true"
                                     style="border:none;background:transparent;box-shadow:none;height:auto;margin-left: 10px;"><span>记住我</span>
                <a href="${ctx}/forgetpass" style="color:#55afed;text-decoration:underline;float:right;margin-top: 12px;">忘记密码?</a>
            </div>
            <input type="hidden" name="openid" value="">
            <div style="float: left; margin-top: 10px;width: 100%;text-align: left;margin-left:40px;">
                <c:if test="${!empty(error)}">
                    <i class="ace-icon fa fa-times-circle"></i>
                    <span style="color: red">${error}</span>
                </c:if>
            </div>
            <button type="button" onclick="submitReq();">登 录</button>
        </form>

    </div>

</div>

<div class="footer">
    <h3>青岛工业软件研究所（中国科学院软件研究所青岛分部）</h3>
    <p>备案号：鲁ICP备XXXXXXXX号</p>
</div>


<script type="text/javascript">
    var login = "${base}";
    function submitReq() {
        var upname = $("#username").val();
        var pwd= $("#password").val();
        var rememberMe = document.getElementsByName("rememberMe");
        addCookie("remember", rememberMe[0].checked, 7, "/");
        if (rememberMe[0].checked) {
            addCookie("username", base64_encode(utf16to8(upname)), 7, "/");
            //addCookie("password", base64_encode(utf16to8(pwd)), 7, "/");
        } else {
            deleteCookie("username", "/");
            //deleteCookie("password", "/");
        }
        /*             $.ajax({type:'POST','/admin/logon.do',data:{KEYDATA:code,tm:new Date().getTime()},
         dataType:'json',success:function(data, textStatus) {
         dialogloadingClose();
         var result=data.result;
         if ("success" != result) {  //如果登录不成功，则再次刷新验证码
         dialogloadingClose();
         clearLoginForm();//清除信息
         loginAlert(result);
         }else{
         window.location.href=jypath+"/backstage/index";
         }
         }
         }); */
        $("#form").submit();
    }

    /**添加设置cookie**/
    function addCookie(name, value, days, path) {
        //username-password-天数-路径
        var name = escape(name);
        var value = escape(value);
        var expires = new Date();
        expires.setTime(expires.getTime() + days * 3600000 * 24);
        //path=/，表示cookie能在整个网站下使用，path=/temp，表示cookie只能在temp目录下使用
        path = path == "" ? "" : ";path=" + path;
        //GMT(Greenwich Mean Time)是格林尼治平时，现在的标准时间，协调世界时是UTC
        //参数days只能是数字型
        var _expires = (typeof days) == "string" ? "" : ";expires=" + expires.toUTCString();
        document.cookie = name + "=" + value + _expires + path;
    }
    function quxiao() {
        $("#username").val('');
        $("#password").val("");
        $("#captcha").val('');
    }
</script>
<script type="text/javascript">

    /**实现功能，保存用户的登录信息到cookie中。当登录页面被打开时，就查询cookie**/
    if (isBrowserErr()) {
        location.href = "${base}browserr.jsp";
    }
    var logname = "";
    window.onload = function () {
        var remember = getCookieValue("remember");
        if (remember == "true") {
            document.getElementById("rememberMe").checked = true;
            var usernameValue = getCookieValue("username");
            if (usernameValue != "") {
                $("#username").val(utf8to16(base64_decode(usernameValue)));
            }
            var pwdValue = getCookieValue("password");
            if (pwdValue != "") {
                $("#password").val(utf8to16(base64_decode(pwdValue)));
            }
            $('input, textarea').placeholder();
        } else {
            $('input, textarea').placeholder();
        }
    }
    /**获取cookie的值，根据cookie的键获取值**/
    function getCookieValue(name) {
        //用处理字符串的方式查找到key对应value
        var name = escape(name);
        //读cookie属性，这将返回文档的所有cookie
        var allcookies = document.cookie;
        //查找名为name的cookie的开始位置
        name += "=";
        var pos = allcookies.indexOf(name);
        //如果找到了具有该名字的cookie，那么提取并使用它的值
        //如果pos值为-1则说明搜索"version="失败
        if (pos != -1) {
            //cookie值开始的位置
            var start = pos + name.length;
            //从cookie值开始的位置起搜索第一个";"的位置,即cookie值结尾的位置
            var end = allcookies.indexOf(";", start);
            //如果end值为-1说明cookie列表里只有一个cookie
            if (end == -1) end = allcookies.length;
            //提取cookie的值
            var value = allcookies.substring(start, end);
            //对它解码
            return (value);
        } else {  //搜索失败，返回空字符串
            return "";
        }
    }
    /**根据cookie的键，删除cookie，其实就是设置其失效**/
    function deleteCookie(name, path) {
        var name = escape(name);
        var expires = new Date(0);
        path = path == "" ? "" : ";path=" + path;
        document.cookie = name + "=" + ";expires=" + expires.toUTCString() + path;
    }
    document.onkeydown = keyDownSearch;

    function keyDownSearch(e) {
        // 兼容FF和IE和Opera
        var theEvent = e || window.event;
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code == 13) {
            submitReq();//具体处理函数
            return false;
        }
        return true;
    }

    function check() {
        if ($("#username").val() == "") {
            $("#username").tips({
                side: 2,
                msg: '用户名不得为空',
                bg: '#AE81FF',
                time: 3
            });
            setTimeout(function () {
                $("#username").focus();
            }, 100)
            return false;
        } else {
            $("#username").val(jQuery.trim($('#username').val()));
        }

        if ($("#password").val() == "") {
            $("#password").tips({
                side: 2,
                msg: '密码不得为空',
                bg: '#AE81FF',
                time: 3
            });
            $("#password").focus();
            //document.getElementById("password").focus();
            return false;
        }

        if ($("#captcha").val() == "") {
            $("#captcha").tips({
                side: 2,
                msg: '验证码不得为空',
                bg: '#AE81FF',
                time: 3
            });
            $("#captcha").focus();
            return false;
        }

        $("#username").tips({
            side: 1,
            msg: '正在登录 , 请稍后 ...',
            bg: '#68B500',
            time: 1000
        });
        return true;
    }

    //刷新验证码
    function changeCode(){
        $("#captchaImage").attr("src", "${ctx}/genVerCode?timestamp=" + (new Date()).valueOf());
    }
</script>
<script>
    //TOCMAT重启之后 点击左侧列表跳转登录首页
    if (window != top) {
        top.location.href = location.href;
    }
</script>
<script type="text/javascript" src="${ctx}/assets/admin/LingUI/login/js/jquery.tips.js"></script>
<script type="text/javascript" src="${ctx}/assets/admin/LingUI/login/js/base64.js"></script>
<script type="text/javascript">
    $(function () {
        $.backstretch("${ctx}/assets/admin/LingUI/login/images/beijing.png");
    });
</script>
</body>
</html>
